package com.ship.dispatch.service.report.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.dispatch.bean.report.SpWorkbenchMenu;
import com.ship.dispatch.mapper.report.SpWorkbenchMenuMapper;
import com.ship.dispatch.service.report.SpWorkbenchMenuService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SpWorkbenchMenuServiceImpl extends BaseServiceImpl<SpWorkbenchMenuMapper, SpWorkbenchMenu> implements SpWorkbenchMenuService {

    /**
     * 保存个人工作台快捷菜单
     */
    @Override
    public void saveWorkbenchMenu(String content){
        SpWorkbenchMenu menu = this.getOne(new LambdaQueryWrapper<SpWorkbenchMenu>().eq(SpWorkbenchMenu::getCreateBy, SecurityUtils.getStringUserId()));
        if(null != menu){
          Boolean judge = this.removeById(menu);
          if(judge){
              saveMenu(content);
          }
        }else{
            saveMenu(content);
        }
    }

    private void saveMenu(String content) {
        SpWorkbenchMenu spWorkbenchMenu = new SpWorkbenchMenu();
        spWorkbenchMenu.setCreateBy(SecurityUtils.getStringUserId());
        spWorkbenchMenu.setWorkbenchContent(content);
        spWorkbenchMenu.setCreateDate(new Date());
        this.save(spWorkbenchMenu);
    }

    /**
     * 获取个人工作台快捷菜单
     */
    @Override
    public SpWorkbenchMenu getWorkbenchMenu(){
        SpWorkbenchMenu menu = this.getOne(new LambdaQueryWrapper<SpWorkbenchMenu>().eq(SpWorkbenchMenu::getCreateBy, SecurityUtils.getStringUserId()));
        return menu;
    }
}
